package com.example.calendarapp;

import android.content.Context;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.widget.Toast;

public class SwipeDetector extends SimpleOnGestureListener { 
	private static final int SWIPE_MIN_DISTANCE = 80;
	private static final int SWIPE_MAX_OFF_PATH = 250;
	private static final int SWIPE_THRESHOLD_VELOCITY = 100;
	private Context context;
	
	public SwipeDetector(Context ctx)
	{
		this.context = ctx;
	}
	
	@Override 
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        try { 
            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)                 
            // right to left swipe 
            if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            	leftSwipe();
            }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            	rightSwipe();
            } 
        } catch (Exception e) {
            // nothing 
        } 
        return false; 
    } 

        @Override 
    public boolean onDown(MotionEvent e) {
          return true; 
    }
        
    public void leftSwipe()
    {
    	Toast.makeText(context, "Left Swipe", Toast.LENGTH_SHORT).show();
    }
    
    public void rightSwipe()
    {
    	Toast.makeText(context, "Left Swipe", Toast.LENGTH_SHORT).show();
    }
} 